<%@ page import="com.google.appengine.api.users.User,com.google.appengine.api.users.UserService,com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="utils.UsersInfo" %>

<%
	UserService userService = UserServiceFactory.getUserService();
	User user = userService.getCurrentUser();	
	String strUser_EmailID, strLogout_Link, strUser_FullName;
	strUser_EmailID = strLogout_Link = strUser_FullName = "";
	
    if (user != null) 
    {
    	strUser_EmailID = user.getEmail().toLowerCase();
    	if ( strUser_EmailID.indexOf("celestica.com") < 0)
    	{
    		response.sendRedirect("/logout.jsp?error_msg=[ADMIN] You are not authorised to view this site");
    	}else {
    		strLogout_Link = userService.createLogoutURL(request.getRequestURI());
    		strUser_FullName = UsersInfo.getFullName(strUser_EmailID);    		
    	}
    }else{

    	String url = userService.createLoginURL(request.getRequestURI());
        String host_url = request.getRequestURL().toString().substring(0, (request.getRequestURL().toString().length()) - (request.getRequestURI().toString().length()) );       
        host_url = host_url + url; 
        response.sendRedirect(url);    	
    }    
	pageContext.setAttribute("USER_EMAILID", strUser_EmailID, PageContext.PAGE_SCOPE);
	pageContext.setAttribute("USER_FULLNAME", strUser_FullName, PageContext.PAGE_SCOPE);
	pageContext.setAttribute("LOGOUT_LINK", strLogout_Link, PageContext.PAGE_SCOPE);    
%>